package com.nannybear.View;

import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.nannybear.R;

/**
 * @brief View for the setting
 */
public class SettingsScreen extends Screen {
    /********** DECLARATIONS **********/
    // Widget of the view
    private ScrollView settings_screen_layout;
    private ImageButton choice_name_btn, choice_parameters_btn, choice_connection_btn, choice_sound_btn, choice_light_btn;
    private TextView txt_connection, choice_name, choice_parameter, choice_connection;
    private TextView txt_change_threshold, txt_change_sound, txt_change_light, value_quiet_end, value_noise_start, value_dark_end, value_dim_start, value_dim_end, value_bright_start;
    private Button connection_btn;
    private LinearLayout light_seekbar, bb_name_layout, choice_connection_layout, choice_sound_layout, choice_light_layout;
    private RelativeLayout txt_threshold_light;
    private ImageView wifi_state;

    // Tab buttons
    private ImageButton homeButton;
    private ImageButton tempButton;
    private ImageButton brightnessButton;
    private ImageButton humidityButton;
    private ImageButton babyStateButton;
    private ImageButton settingsButton;
    private ImageButton helpButton;

    // Boolean to detect which tab is open
    private boolean name_open = false;
    private boolean parameter_open = false;
    private boolean connection_open = false;
    private boolean sound_open = false;
    private boolean light_open = false;

    /************ METHODS ************/
    /**
     * @brief constructor.
     */
    public SettingsScreen(){
    }

    /**
     * @brief : Close the choice of the baby's name
     */
    public void closeChoiceName(){
        getChoice_name_btn().setImageResource(R.drawable.down_arrow);
        getChoice_name().setText("Change the name of your baby");
        getChoice_name().setTextColor(Color.parseColor("#D3CDCD"));
        getChoice_name().setTypeface(null, Typeface.ITALIC);
        getBb_name_layout().setVisibility(View.GONE);
    }

    /**
     * @brief : Close the choice of the thresholds modification
     */
    public void closeChoiceParameter(){
        closeChoiceSound();
        closeChoiceLight();
        getChoice_parameters_btn().setImageResource(R.drawable.down_arrow);
        getChoice_parameter().setText("Change the value of thresholds");
        getChoice_parameter().setTextColor(Color.parseColor("#D3CDCD"));
        getChoice_parameter().setTypeface(null, Typeface.ITALIC);
        getTxt_change_threshold().setVisibility(View.GONE);
        getTxt_change_sound().setVisibility(View.GONE);
        getTxt_change_light().setVisibility(View.GONE);
        getChoice_sound_btn().setVisibility(View.GONE);
        getChoice_light_btn().setVisibility(View.GONE);
    }

    /**
     * @brief : Close the choice of the sound modification
     */
    public void closeChoiceSound(){
        getChoice_sound_btn().setImageResource(R.drawable.down_arrow);
        getChoice_sound_layout().setVisibility(View.GONE);
        getTxt_change_sound().setTextColor(Color.parseColor("#D3CDCD"));
    }

    /**
     * @brief : Close the choice of the light modification
     */
    public void closeChoiceLight(){
        getChoice_light_btn().setImageResource(R.drawable.down_arrow);
        getTxt_threshold_light().setVisibility(View.GONE);
        getChoice_light_layout().setVisibility(View.GONE);
        getTxt_change_light().setTextColor(Color.parseColor("#D3CDCD"));
    }

    /**
     * @brief : Close the choice of the test connection
     */
    public void closeChoiceConnection(){
        getChoice_connection_btn().setImageResource(R.drawable.down_arrow);
        getChoice_connection().setText("Connection problem");
        getChoice_connection().setTextColor(Color.parseColor("#D3CDCD"));
        getChoice_connection().setTypeface(null, Typeface.ITALIC);
        getChoice_connection_layout().setVisibility(View.GONE);
    }

    /**
     * @brief : Display or not the part of the baby's name modification
     */
	public void displayNameButtonClick(){
        // Open the tab
    	 if(name_open == false){
             name_open = true;
             getChoice_name_btn().setImageResource(R.drawable.up_arrow);
             getChoice_name().setText("CHANGE THE NAME OF YOUR BABY");
             getChoice_name().setTextColor(Color.parseColor("#FFFFFF"));
             getChoice_name().setTypeface(null, Typeface.BOLD);
             getBb_name_layout().setVisibility(View.VISIBLE);
         }
         // Close the tab
         else{
             name_open = false;
             closeChoiceName();
         }
    }

    /**
     * @brief : Display or not the part of the thresholds modification
     */
    public void displayParameterButtonClick(){
        // Open the tab
        if(parameter_open == false){
            parameter_open = true;
            getChoice_parameters_btn().setImageResource(R.drawable.up_arrow);
            getChoice_parameter().setText("CHANGE THE VALUE OF THRESHOLDS");
            getChoice_parameter().setTextColor(Color.parseColor("#FFFFFF"));
            getChoice_parameter().setTypeface(null, Typeface.BOLD);
            getTxt_change_threshold().setVisibility(View.VISIBLE);
            getTxt_change_sound().setVisibility(View.VISIBLE);
            getTxt_change_light().setVisibility(View.VISIBLE);
            getChoice_sound_btn().setVisibility(View.VISIBLE);
            getChoice_light_btn().setVisibility(View.VISIBLE);
        }
        // Close the tab
        else{
            parameter_open = false;
            closeChoiceParameter();
        }
    }

    /**
     * @brief : Display or not the part of the sound modification
     */
    public void displaySoundButtonClick(){
        // Open the tab
        if(sound_open == false){
            sound_open=true;
            getChoice_sound_btn().setImageResource(R.drawable.up_arrow);
            getTxt_change_sound().setTextColor(Color.parseColor("#FFFFFF"));
            getChoice_sound_layout().setVisibility(View.VISIBLE);
        }
        // Close the tab
        else{
            sound_open=false;
            closeChoiceSound();
        }
    }

    /**
     * @brief : Display or not the part of the light modification
     */
    public void displayLightButtonClick(){
        // Open the tab
        if(light_open == false){
            light_open=true;
            getChoice_light_btn().setImageResource(R.drawable.up_arrow);
            getTxt_threshold_light().setVisibility(View.VISIBLE);
            getTxt_change_light().setTextColor(Color.parseColor("#FFFFFF"));
            getChoice_light_layout().setVisibility(View.VISIBLE);
        }
        // Close the tab
        else{
            light_open=false;
            closeChoiceLight();
        }
    }

    /**
     * @brief : Display or not the part of the connection attempt
     */
    public void displayConnectionButtonClick(){
        // Open the tab
        if(connection_open == false){
            connection_open = true;
            getChoice_connection_btn().setImageResource(R.drawable.up_arrow);
            getChoice_connection().setText("CONNECTION PROBLEM");
            getChoice_connection().setTextColor(Color.parseColor("#FFFFFF"));
            getChoice_connection().setTypeface(null, Typeface.BOLD);
            getChoice_connection_layout().setVisibility(View.VISIBLE);
        }
        // Close the tab
        else{
            connection_open = false;
            closeChoiceConnection();
        }
    }

    /**
     * @brief Show the view
     */
    public void display(){
        getChoice_name_btn().setImageResource(R.drawable.down_arrow);
        getChoice_parameters_btn().setImageResource(R.drawable.down_arrow);
        getChoice_connection_btn().setImageResource(R.drawable.down_arrow);
        getSettings_screen_layout().setVisibility(View.VISIBLE);
        wifi_state.setVisibility(View.VISIBLE);
        getSettingsButton().setBackgroundResource(R.drawable.settings_active);
    }

    /**
     * @brief Change the value of the sound TextView when the user move the cursor on the seekBar
     */
    public void displayValueSound(int newValue){
        getValue_quiet_end().setText(String.valueOf(newValue));
        getValue_noise_start().setText(String.valueOf(newValue));
    }

    /**
     * @brief Change the value of the light TextView when the user move the cursor on the seekBar
     */
    public void displayValueLight(int newValueDarkDim, int newValueDimBright){
        getValue_dark_end().setText(String.valueOf(newValueDarkDim));
        getValue_dim_start().setText(String.valueOf(newValueDarkDim));
        getValue_dim_end().setText(String.valueOf(newValueDimBright));
        getValue_bright_start().setText(String.valueOf(newValueDimBright));
    }

    /**
     * @brief Close the view
     */
    public void close(){
        getSettings_screen_layout().setVisibility(View.GONE);
        wifi_state.setVisibility(View.GONE);
        closeChoiceName();
        closeChoiceParameter();
        closeChoiceConnection();
        getSettingsButton().setBackgroundResource(R.drawable.settings_grey);
    }


    /*********** ACCESSORS ***********/
    public void setHomeButton(ImageButton homeBtn) {
        this.homeButton = homeBtn;
    }

    public ImageButton getHomeButton() {
        return homeButton;
    }

    public void setTempButton(ImageButton tempBtn) {
        this.tempButton = tempBtn;
    }

    public ImageButton getTempButton() {
        return tempButton;
    }

    public void setBrightnessButton(ImageButton brightnessBtn) {
        this.brightnessButton = brightnessBtn;
    }

    public ImageButton getBrightnessButton() {
        return brightnessButton;
    }

    public void setHumidityButton(ImageButton humidityBtn) {
        this.humidityButton = humidityBtn;
    }

    public ImageButton getHumidityButton() {
        return humidityButton;
    }

    public void setBabyStateButton(ImageButton babyStateBtn) {
        this.babyStateButton = babyStateBtn;
    }

    public ImageButton getBabyStateButton() {
        return babyStateButton;
    }

    public void setSettingsButton(ImageButton settingsBtn) {
        this.settingsButton = settingsBtn;
    }

    public ImageButton getSettingsButton() {
        return settingsButton;
    }

    public void setHelpButton(ImageButton helpBtn) {
        this.helpButton = helpBtn;
    }

    public ImageButton getHelpButton() {
        return helpButton;
    }

    public void setChoice_name_btn(ImageButton choice_name_btn) {
        this.choice_name_btn = choice_name_btn;
    }

    public ImageButton getChoice_name_btn() {
        return choice_name_btn;
    }

    public void setChoice_parameters_btn(ImageButton choice_parameters_btn) {
        this.choice_parameters_btn = choice_parameters_btn;
    }

    public ImageButton getChoice_parameters_btn() {
        return choice_parameters_btn;
    }

    public void setChoice_connection_btn(ImageButton choice_connection_btn) {
        this.choice_connection_btn = choice_connection_btn;
    }

    public ImageButton getChoice_connection_btn() {
        return choice_connection_btn;
    }

    public TextView getChoice_name() {
        return choice_name;
    }

    public void setChoice_name(TextView choice_name) {
        this.choice_name = choice_name;
    }

    public TextView getChoice_parameter() {
        return choice_parameter;
    }

    public void setChoice_parameter(TextView choice_parameter) {
        this.choice_parameter = choice_parameter;
    }

    public TextView getChoice_connection() {
        return choice_connection;
    }

    public void setChoice_connection(TextView choice_connection) {
        this.choice_connection = choice_connection;
    }

	public ScrollView getSettings_screen_layout() {
		return settings_screen_layout;
	}

	public void setSettings_screen_layout(ScrollView settings_screen_layout) {
		this.settings_screen_layout = settings_screen_layout;
	}

    public TextView getTxt_connection() {
        return txt_connection;
    }

    public void setTxt_connection(TextView txt_connection) {
        this.txt_connection = txt_connection;
    }

    public void setConnection_btn(Button connection_btn) {
        this.connection_btn = connection_btn;
    }

    public Button getConnection_btn() {
        return connection_btn;
    }

    public void setWifi_state(ImageView wifi_state) {
        this.wifi_state = wifi_state;
    }

    public ImageView getWifi_state() {
        return wifi_state;
    }

    public void setLight_seekbar(LinearLayout light_seekbar) {
        this.light_seekbar = light_seekbar;
    }

    public LinearLayout getLight_seekbar() {
        return light_seekbar;
    }

    public LinearLayout getBb_name_layout() {
        return bb_name_layout;
    }

    public void setBb_name_layout(LinearLayout bb_name_layout) {
        this.bb_name_layout = bb_name_layout;
    }

    public LinearLayout getChoice_connection_layout() {
        return choice_connection_layout;
    }

    public void setChoice_connection_layout(LinearLayout choice_connection_layout) {
        this.choice_connection_layout = choice_connection_layout;
    }

    public TextView getTxt_change_threshold() {
        return txt_change_threshold;
    }

    public void setTxt_change_threshold(TextView txt_change_threshold) {
        this.txt_change_threshold = txt_change_threshold;
    }

    public TextView getTxt_change_sound() {
        return txt_change_sound;
    }

    public void setTxt_change_sound(TextView txt_change_sound) {
        this.txt_change_sound = txt_change_sound;
    }

    public TextView getTxt_change_light() {
        return txt_change_light;
    }

    public void setTxt_change_light(TextView txt_change_light) {
        this.txt_change_light = txt_change_light;
    }

    public ImageButton getChoice_sound_btn() {
        return choice_sound_btn;
    }

    public void setChoice_sound_btn(ImageButton choice_sound_btn) {
        this.choice_sound_btn = choice_sound_btn;
    }

    public ImageButton getChoice_light_btn() {
        return choice_light_btn;
    }

    public void setChoice_light_btn(ImageButton choice_light_btn) {
        this.choice_light_btn = choice_light_btn;
    }

    public LinearLayout getChoice_sound_layout() {
        return choice_sound_layout;
    }

    public void setChoice_sound_layout(LinearLayout choice_sound_layout) {
        this.choice_sound_layout = choice_sound_layout;
    }

    public LinearLayout getChoice_light_layout() {
        return choice_light_layout;
    }

    public void setChoice_light_layout(LinearLayout choice_light_layout) {
        this.choice_light_layout = choice_light_layout;
    }

    public RelativeLayout getTxt_threshold_light() {
        return txt_threshold_light;
    }

    public void setTxt_threshold_light(RelativeLayout txt_threshold_light) {
        this.txt_threshold_light = txt_threshold_light;
    }

    public TextView getValue_quiet_end() {
        return value_quiet_end;
    }

    public void setValue_quiet_end(TextView value_quiet_end) {
        this.value_quiet_end = value_quiet_end;
    }

    public TextView getValue_noise_start() {
        return value_noise_start;
    }

    public void setValue_noise_start(TextView value_noise_start) {
        this.value_noise_start = value_noise_start;
    }

    public TextView getValue_dark_end() {
        return value_dark_end;
    }

    public void setValue_dark_end(TextView value_dark_end) {
        this.value_dark_end = value_dark_end;
    }

    public TextView getValue_dim_start() {
        return value_dim_start;
    }

    public void setValue_dim_start(TextView value_dim_start) {
        this.value_dim_start = value_dim_start;
    }

    public TextView getValue_dim_end() {
        return value_dim_end;
    }

    public void setValue_dim_end(TextView value_dim_end) {
        this.value_dim_end = value_dim_end;
    }

    public TextView getValue_bright_start() {
        return value_bright_start;
    }

    public void setValue_bright_start(TextView value_bright_start) {
        this.value_bright_start = value_bright_start;
    }
}
